'use strict';

module.exports = {
  async up (queryInterface, Sequelize) {
    const { INTEGER,DATE,TEXT } = Sequelize;
    await queryInterface.createTable('moment_comment', {
      id:{
        type: INTEGER(20).UNSIGNED, 
        primaryKey: true, 
        autoIncrement: true
      },
      user_id:{
        type: INTEGER(20).UNSIGNED, 
        allowNull: false, 
        comment: "评论用户id",
        // 外键
        references: {
          model: 'user',
          key: 'id'
        },
        onUpdate: 'restrict', // 更新时操作
        onDelete: 'cascade' // 删除时操作
      },
      moment_id: {
        type: INTEGER(20).UNSIGNED, 
        allowNull: false,
        comment: "朋友圈消息id",
        // 外键
        references: {
          model: 'moment',
          key: 'id'
        },
        onUpdate: 'restrict', // 更新时操作
        onDelete: 'cascade' // 删除时操作
      },
      content: {
        type: TEXT,
        allowNull: false,
        defaultValue: '',
        comment: '评论内容'
      },
      reply_id: {
        type: INTEGER(20).UNSIGNED, 
        allowNull: false,
        defaultValue: 0,
        comment: '回复用户id 0顶级评论'
      },
      created_at: DATE,
      updated_at: DATE
    })
  },

  async down (queryInterface, Sequelize) {
    await queryInterface.dropTable('moment_comment')

  }
};
